package rlm.rlcontainer;

import alm.XTab;
import alm.YTab;

public class HorizontalPlaceHolder extends BiPartitionPlaceHolder<YTab> {

	public HorizontalPlaceHolder(PlaceHolder a, PlaceHolder b) {
		super(a, b);
	}
	
	protected void addInnerRelation(){
		getTopPlace().addBottom(getTopPlace());
		getBottomPlace().addLeft(getBottomPlace());
	}
	
	public PlaceHolder getTopPlace(){
		return this.get0();
	}
	
	public PlaceHolder getBottomPlace(){
		return this.get1();
	}


	@Override
	public PlaceHolder addBottom(PlaceHolder p) {
		p.addTop(this);
		getBottomPlace().addBottom(p);
		return p;
	}


	@Override
	public PlaceHolder addLeft(PlaceHolder p) {
		getBottomPlace().addLeft(p);
		getTopPlace().addLeft(p);
		return p;
	}


	@Override
	public PlaceHolder addRight(PlaceHolder p) {
		getBottomPlace().addRight(p);
		getTopPlace().addRight(p);
		return p;
	}


	@Override
	public PlaceHolder addTop(PlaceHolder p) {
		getTopPlace().addTop(p);
		return p;
	}

	//----------------------------
	// Tabs
	//----------------------------
	
	@Override
	public void setBottomTab(YTab bottomTab) {
		super.setBottomTab(bottomTab); // needed??
		getBottomPlace().setBottomTab(bottomTab);
	}

	@Override
	public void setLeftTab(XTab leftTab) {
		super.setLeftTab(leftTab);
		getBottomPlace().setLeftTab(leftTab);
		getTopPlace().setLeftTab(leftTab);
	}

	@Override
	public void setRightTab(XTab rightTab) {
		super.setRightTab(rightTab);
		getBottomPlace().setRightTab(rightTab);
		getTopPlace().setRightTab(rightTab);
	}

	@Override
	public void setTopTab(YTab topTab) {
		super.setTopTab(topTab);
		getTopPlace().setTopTab(topTab);
	}

	// ----------
	// inner tab
	// -----------
	@Override
	public void setInnerTab(YTab tab) {
		super.setInnerTab(tab);
		getTopPlace().setBottomTab(tab);
		getBottomPlace().setTopTab(tab);
	}
	
	public int getXCount(){
		return Math.max(getTopPlace().getXCount(), getBottomPlace().getXCount());
	}
	
	public int getYCount(){
		return (getTopPlace().getYCount() + getBottomPlace().getYCount());
	}
	
}
